namespace ColladaDotNet.OpenTKMapping
{
	public class ControllerInstance:DocumentLibraryElement<instance_controller>
	{
		private Controller controller;
		private Sceleton sceleton;

		private BindMaterial material;

		public Controller Controller
		{
			get
			{
				return controller;
			}
		}
		public Skin Skin
		{
			get
			{
				return controller as Skin;
			}
		}
		public Morph Morph
		{
			get
			{
				return controller as Morph;
			}
		}

		public Sceleton Sceleton
		{
			get
			{
				return sceleton;
			}
		}

		internal override void Load(instance_controller colladaData)
		{
			base.Load(colladaData);
			controller = Document.GetElementByUrl<Controller>(colladaData.url);
			if (colladaData.bind_material != null)
			{
				material = Document.CreateElement<BindMaterial>(colladaData.bind_material);
			}
			sceleton = new Sceleton();
			Sceleton.Document = Document;
			Sceleton.Load(colladaData.skeleton);
		}
		public void Render()
		{
			Controller.Render(Sceleton, material);
		}
	}
}